<?php
class app_admin extends app implements interface_app {

    public function pre_dispatch(){

        // Setup URL 
        $this->config->set_section('config');
        $this->url->setURL($this->config->get('http_server'));
        // Url
        if($this->setting->get('config_secure')) {
            $this->url->setSSL($this->config->get('https_server'));
        } 

        $this->setting->set('http_server', $this->config->get('https_server'));
        $this->setting->set('https_server', $this->config->get('https_server'));
        $this->setting->set('http_catalog', $this->config->get('http_catalog'));

        // Router
        if (isset($this->request->get['route'])) {
            $this->action = $this->action($this->request->get['route']);
        }
               
        // Language
        $languages = array();
        $lang_cfg = $this->setting->get('config_admin_language');
        $query = $this->pdo->prepare("SELECT * FROM " . $this->setting->get('db_prefix') . "language"); 
        $query->execute();

        foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $result) {
            $languages[$result['code']] = $result;
        }

        $language = $this->language($languages[$lang_cfg]['directory']); 
        $language->load($languages[$lang_cfg]['filename']);	
        $this->registry->set('language', $language); 
        $this->setting->set('config_language_id', $languages[$lang_cfg]['language_id']);

    }
}
